package io.hx.modules.patient.service.impl;
import io.hx.modules.patient.dao.PatientUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.hx.common.utils.PageUtils;
import io.hx.common.utils.Query;
import io.hx.modules.patient.dao.FilesDao;
import io.hx.modules.patient.entity.FilesEntity;
import io.hx.modules.patient.service.FilesService;


@Service("filesService")
public class FilesServiceImpl extends ServiceImpl<FilesDao, FilesEntity> implements FilesService {

    @Autowired
    private PatientUserDao userDao;
    @Autowired
    private FilesDao filesDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FilesEntity> page = this.page(
                new Query<FilesEntity>().getPage(params),
                new QueryWrapper<FilesEntity>()
        );
        for (FilesEntity record : page.getRecords()) {
            record.setUser(userDao.selectById(record.getUserId()));
            record.setNumberVisit(filesDao.countVisit(record.getUserId()));
        }
        return new PageUtils(page);
    }
    @Override
    public FilesEntity queryByUserId(Integer userId) {

        return filesDao.queryByUserId(userId) ;
    }

    @Override
    public void update1(FilesEntity filesEntity) {
         filesDao.updateByUserId(filesEntity);
    }
}
